package org.fioma.ui;

import java.io.IOException;

import org.fioma.tree.bytes.RootBytes;
import org.fioma.tree.suffixTree.bytes.SuffixTreeBytes;

public class Tools {

	public static final RootBytes buildWordTree(String fileFastQName, int k) throws IOException {
		RootBytes root = new RootBytes();
		FastQ fastQ = new FastQ(fileFastQName, k);
		byte[] dnaSeq;

		int i = 0;
		while ((dnaSeq = fastQ.getNextSeq()) != null) {
			i++;
			root.addWord(dnaSeq);
			if (i % 1000000 == 0) {
				System.out.println(i);
			}
		}

		System.out.println(i);
		return root;
	}

	public static final SuffixTreeBytes buildSuffixTree(FastQ fastQ, SuffixTreeBytes tree) throws IOException {
		byte[] dnaSeq;
		long timeInic = System.currentTimeMillis();
		long time = timeInic;
		long timeAux;
		System.out.println("Starting:" + fastQ.fileFastQName);
		int i = 0;
		while ((dnaSeq = fastQ.getNextSeq()) != null) {
			i++;
			tree.addSuffixes(dnaSeq);

			if (i % 100000 == 0) {
				timeAux = System.currentTimeMillis();
				System.out.println(i + " , Total time for this file: " + (timeAux - timeInic) + " , delta: " + (timeAux - time));
			}
		}

		System.out.println(i);
		System.out.println("Finished:" + fastQ.fileFastQName);
		System.out.println();
		return tree;
	}
}
